package com.charger.cooperation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.charger.common.annotation.Log;
import com.charger.common.core.controller.BaseController;
import com.charger.common.core.domain.AjaxResult;
import com.charger.common.enums.BusinessType;
import com.charger.cooperation.domain.Projects;
import com.charger.cooperation.service.IProjectsService;
import com.charger.common.utils.poi.ExcelUtil;
import com.charger.common.core.page.TableDataInfo;

/**
 * 加盟项目Controller
 * 
 * @author ruoyi
 * @date 2024-11-23
 */
@RestController
@RequestMapping("/cooperation/projects")
public class ProjectsController extends BaseController
{
    @Autowired
    private IProjectsService projectsService;

    /**
     * 查询加盟项目列表
     */
    @PreAuthorize("@ss.hasPermi('cooperation:projects:list')")
    @GetMapping("/list")
    public TableDataInfo list(Projects projects)
    {
        startPage();
        List<Projects> list = projectsService.selectProjectsList(projects);
        return getDataTable(list);
    }

    @GetMapping("/unrelated")
    public TableDataInfo unrelated( Projects projects)
    {
        List<Projects> projectsList = projectsService.getUnrelatedChargerList(projects);
        return getDataTable(projectsList);
    }

    /**
     * 导出加盟项目列表
     */
    @PreAuthorize("@ss.hasPermi('cooperation:projects:export')")
    @Log(title = "加盟项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Projects projects)
    {
        List<Projects> list = projectsService.selectProjectsList(projects);
        ExcelUtil<Projects> util = new ExcelUtil<Projects>(Projects.class);
        util.exportExcel(response, list, "加盟项目数据");
    }

    /**
     * 获取加盟项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('cooperation:projects:query')")
    @GetMapping(value = "/{projectsId}")
    public AjaxResult getInfo(@PathVariable("projectsId") Long projectsId)
    {
        return success(projectsService.selectProjectsByProjectsId(projectsId));
    }

    /**
     * 新增加盟项目
     */
    @PreAuthorize("@ss.hasPermi('cooperation:projects:add')")
    @Log(title = "加盟项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Projects projects)
    {
        return toAjax(projectsService.insertProjects(projects));
    }

    /**
     * 修改加盟项目
     */
    @PreAuthorize("@ss.hasPermi('cooperation:projects:edit')")
    @Log(title = "加盟项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Projects projects)
    {
        return toAjax(projectsService.updateProjects(projects));
    }

    /**
     * 删除加盟项目
     */
    @PreAuthorize("@ss.hasPermi('cooperation:projects:remove')")
    @Log(title = "加盟项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectsIds}")
    public AjaxResult remove(@PathVariable Long[] projectsIds)
    {
        return toAjax(projectsService.deleteProjectsByProjectsIds(projectsIds));
    }
}
